<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">

    <title>验证码</title>
    <style>
        
        #verificationCodeImg{
            vertical-align: middle;
        }
        
		
		body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
        }
        .register-container {
            max-width: 300px;
            margin: 50px auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        
        
        #checkCaptcha {
            width: 100%;
            padding: 10px;
            border: none;
            border-radius: 4px;
            background-color: #5cb85c;
            color: white;
            cursor: pointer;
        }
        
    </style>
</head>

<body>

<div id="confirm" class="register-container">
	<h1>输入验证码</h1>
    <img id="verificationCodeImg" src="/captcha/getCaptcha" style="cursor: pointer;" title="看不清？换一张" />
    <input type="text" name="inputCaptcha" id="inputCaptcha">
    <input type="button" value="提交" id="checkCaptcha">
</div>
<script src="./js/jquery-3.7.1.js"></script>
<script>
    $("#verificationCodeImg").click(function(){
        $(this).hide().attr('src', '/captcha/getCaptcha?dt=' + new Date().getTime()).fadeIn();
    });

    $("#checkCaptcha").click(function () {
        $.ajax({
            type:"post",
            url:"/captcha/check",
            data:{

                //这里向check方法中传参,captcha: 用户输入前端的验证码

                captcha: $("#inputCaptcha").val()
            },
            success:function (result){
                if (result){
                    location.href = "success.html"
                }else{
                    alert("验证码校验错误或已过期");
                }
            }
        });
    });

</script>
</body>

</html>